﻿@*
    文件
*@

@using System.Diagnostics;
@using NewLife.Common;
@using NewLife.Cube.Areas.Admin;
@using NewLife;
@{
    var fs = Model as List<FileItem>;
    var r = ViewBag.Current as String;
    var clips = ViewBag.Clip as ICollection<FileItem>;
}

<div class="card">
    <form action="~/Admin/File" id="tool" method="post">
        <div class="card-header pt-5">
            <div class="card-title d-flex align-items-center">
                <div class="input-group mb-5 input-group-sm">
@*                    <span class="input-group-text" id="basic-addon3">
                        <i class="las la-wallet fs-1"></i>
                    </span>*@
                    <input type="search" class="form-control" id="r" name="r" value="@r" placeholder="当前路径">
                    <button type="submit" class="input-group-text bg-light-warning hoverable text-info ms-2">
                        <i class="fas fa-folder-open fs-4 me-2 text-info"></i>
                        <span class="">打 开</span>
                    </button>
                </div>

                <div class="input-group mb-5 input-group-sm px-5">
                    <input type="file" class="form-control" id="file" name="file" placeholder="上传文件">
                    <button type="submit" class="input-group-text bg-light-primary hoverable text-info ms-2" onclick="$('#tool').attr('action', '/Admin/File/Upload');$('#tool').attr('enctype', 'multipart/form-data'); return true;">
                        <i class="fas fa-upload fs-4 me-2 text-info"></i>
                        <span class="">上 传</span>
                    </button>
                </div>
            </div>

            <div class="card-toolbar">
                @if (clips.Count > 0)
                {
                    <div class="text-end mb-4">
                        <a href="/Admin/File/Paste?r=@r" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-primary btn-active-light-primary">粘贴</a>
                        <a href="/Admin/File/Move?r=@r" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-success btn-active-light-success">移动</a>
                        <a href="/Admin/File/ClearClipboard?r=@r" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-info btn-active-light-info">清空</a>

                    </div>
                    <div class="text-end">
                        <span class="input-group-addon">
                            <i class="fas fa-hdd pe-3" data-bs-toggle="tooltip" title="剪切板共有 @clips.Count 项">&nbsp;&nbsp;  @clips.Count</i>
                        </span>
                    </div>
                }
            </div>
        </div>
    </form>

    <div class="card-body">
        <div class="table-responsive dataTables_wrapper dt-bootstrap4">
            <table class="table table-hover table-row-bordered table-row-dashed gy-4">
                <thead>
                    <tr class="fs-4 text-muted">
                        <th><a href="~/Admin/File?r=@r&sort=name">名称</a></th>
                        <th class="text-right"><a href="~/Admin/File?r=@r&sort=size">大小</a></th>
                        <th><a href="~/Admin/File?r=@r&sort=lastwrite">修改时间</a></th>
                        <th class="text-center">复制</th>
                        <th class="text-center">压缩</th>
                        <th class="text-center">删除</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in fs)
                    {
                        <tr>
                            @if (item.Directory)
                            {
                                <td><a href="~/Admin/File?r=@item.FullName" data-bs-toggle="tooltip" title="进入目录">@item.Name</a></td>
                            }
                            else
                            {
                                <td><a href="~/Admin/File/Download?r=@item.FullName" data-bs-toggle="tooltip" title="下载文件">@item.Name</a></td>
                            }
                            <td class="text-right">@item.Size</td>
                            <td>@item.LastWrite.ToFullString("")</td>
                            <td class="text-center">
                                @if (!clips.Any(e => e.FullName == item.FullName))
                                {
                                    <a href="~/Admin/File/Copy?r=@r&f=@item.FullName" data-bs-toggle="tooltip" title="复制到剪切板，然后去目标目录粘贴">复制</a>
                                }
                                else
                                {
                                    <a href="~/Admin/File/CancelCopy?r=@r&f=@item.FullName" data-bs-toggle="tooltip" title="从剪切板移除">取消复制</a>
                                }
                            </td>
                            @if (item.Name.EndsWithIgnoreCase(".zip"))
                            {
                                <td class="text-center"><a href="~/Admin/File/Decompress?r=@item.FullName" data-bs-toggle="tooltip" title="解压缩到当前目录">解压缩</a></td>
                            }
                            else
                            {
                                <td class="text-center"><a href="~/Admin/File/Compress?r=@item.FullName" data-bs-toggle="tooltip" title="压缩到当前目录，加上时间后缀">压缩</a></td>
                            }
                            <td class="text-center"><a href="~/Admin/File/Delete?r=@item.FullName" onclick="return confirm('确认删除？');">删除</a></td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>





